// 增加数据，当增加多条数据的时候option为一个数组
exports.addOneDoc = function( obj ) {
    const {model, option, callback} = obj
    model.create(option,function (err,data) {
        const result = {
            code: '200'
        }
        if (err){
            console.log(err)
            result.msg = 'error'
            result.data = err
            callback(result)
        }else {
            result.msg = 'success'
            result.data = data
            callback(result)
        }
    })
}

// 查询一条数据
exports.findOneDoc = function( obj ) {
    const {model, option, attachOption, callback} = obj
    model.findOne(option, attachOption, function (err,data) {
        const result = {
            code: '200'
        }
        if (err){
            console.log(err)
            result.msg = 'error'
            result.data = err
            callback(result)
        }else {
            result.msg = 'success'
            result.data = data
            callback(result)
        }
    })
}

// 查询多条数据
exports.findManyDoc = function( obj ) {
    const {model, option, attachOption, callback} = obj
    model.find(option, attachOption, function (err,data) {
        const result = {
            code: '200'
        }
        if (err){
            console.log(err)
            result.msg = 'error'
            result.data = err
            callback(result)
        }else {
            result.msg = 'success'
            result.data = data
            callback(result)
        }
    })
}

// 删除数据,删除多条传递一个数组
exports.removeOneDoc = function( obj ) {
    const {model, option, callback} = obj
    model.remove(option,function (err,data) {
        const result = {
            code: '200'
        }
        if (err){
            console.log(err)
            result.msg = 'error'
            result.data = err
            callback(result)
        }else {
            result.msg = 'success'
            result.data = data
            callback(result)
        }
    })
}

// 修改数据
exports.updateDoc = function( obj ) {
    const {model, query, option, attachOption, callback} = obj
    model.updateAndDelete(query, option, attachOption,function (err, data) {
        const result = {
            code: '200'
        }
        if (err){
            console.log(err)
            result.msg = 'error'
            result.data = err
            callback(result)
        }else {
            result.msg = 'success'
            result.data = data
            callback(result)
        }
    })
}
